home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / CONTROL.H < prev    next >
C/C++ Source or Header  |  1980-01-03  |  4KB  |  109 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Controls provide an interface to selecting and executing some action.
  25.  */
  26.  
  27. #ifndef control_h
  28. #define control_h
  29.  
  30. #include <InterViews/scene.h>
  31. #include <InterViews/subject.h>
  32.  
  33. class Control;
  34. class ControlState;
  35.  
  36. class Control : public MonoScene {
  37. public:
  38.     Control(Interactor*);
  39.     Control(const char* name, Interactor*);
  40.     ~Control();
  41.  
  42.     ControlState* State() { return state; }
  43.     void SetState(ControlState*);
  44.  
  45.     virtual void Handle(Event&);
  46.  
  47.     virtual void Select();    /* highlight, open, and grab */
  48.     virtual void Unselect();    /* close, unhighlight */
  49.  
  50.     virtual void Do();        /* action for selection */
  51. protected:
  52.     virtual void Down();    /* activate control */
  53.     virtual void Enter();    /* select a control if active */
  54.     virtual void Open();    /* open subviews, if any */
  55.     virtual void Grab();    /* read input events */
  56.     virtual void Skip();    /* ignore input until enters active control */
  57.     virtual void Leave();    /* unselect if active */
  58.     virtual void Close();    /* close subviews, if any */
  59.     virtual void Up();        /* deactivate control, exec selection */
  60.  
  61.     virtual boolean IsGrabbing(Interactor*);
  62. private:
  63.     ControlState* state;
  64. private:
  65.     void Init(const char*, Interactor*);
  66. };
  67.  
  68. /*
  69.  * ControlState is a subject that several controls share to exchange
  70.  * common information.
  71.  */
  72.  
  73. enum ControlStatus { ControlActive = 0x1 };
  74.  
  75. class ControlState : public Subject {
  76. public:
  77.     ControlState(unsigned status = 0);
  78.     ~ControlState();
  79.  
  80.     boolean Active() { return Set(ControlActive); }
  81.     void Activate() { Set(ControlActive, true); }
  82.     virtual void Deactivate();
  83.  
  84.     Control* Selection() { return selection; }
  85.     void Selection(Control* c) { selection = c; }
  86.     virtual void NotifySelection(Control*);
  87.  
  88.     Control* Action() { return action; }
  89.     void Action(Control* c) { action = c; }
  90.  
  91.     void Push(ControlState*);
  92.     void Pop();
  93.     ControlState* Next() { return next; }
  94.     ControlState* Prev() { return prev; }
  95. protected:
  96.     unsigned status;
  97.     Control* selection;
  98.     Control* action;
  99.     ControlState* next;
  100.     ControlState* prev;
  101.  
  102.     boolean Set(ControlStatus s) { return (status & s) != 0; }
  103.     void Set(ControlStatus s, boolean b) {
  104.     status = b ? (status | s) : (status & ~s);
  105.     }
  106. };
  107.  
  108. #endif
  109.